package ${escapeKotlinIdentifiers(packageName)}

import com.lib.common.base.mvvm.CommonViewModelFragment
import com.lib.common.constant.INTENT_KEY_PARAM1
import com.lib.common.constant.INTENT_KEY_PARAM2
import androidx.databinding.DataBindingUtil
import android.os.Bundle
import com.lib.framework.entity.Event
import com.lib.framework.manager.LogManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

<#if applicationPackage??>
import ${applicationPackage}.R
import ${applicationPackage}.databinding.${databindingName}
</#if>

/**
 * Copyright (C), 2019-2020
 * FileName: ${fragmentClass}
 * Author: 
 * Date: 2020-01-01 00:00
 * Description: XXX fragment
 * History: 
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
class ${fragmentClass} : CommonViewModelFragment<${viewModelClass}>() {

    companion object {

        /**
         * 发给 fragment 的事件
         */
        const val EVENT_XXX = 1 // XXX 事件

        /**
         * 发送给 activity 的事件，activtiy 需要实现 SendEventToActivityListener 接口
         */
        const val FRAGMENT_EVENT_XXXX = 1 // XXXX事件

        @JvmStatic
        fun newInstance(param1: String, param2: String) = ${fragmentClass}().apply {
            arguments = Bundle().apply {
                putString(INTENT_KEY_PARAM1, param1)
                putString(INTENT_KEY_PARAM2, param2)
            }
        }
    }

<#if generateLayout>
	private var mDataBinding: ${databindingName}? = null
</#if>

    override fun getViewModelClass() = ${viewModelClass}::class.java

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {

<#if generateLayout>
        if (mDataBinding == null) {
            mDataBinding = DataBindingUtil.inflate(inflater, R.layout.${layoutName}, container,
                false)
            mDataBinding?.viewModel = mViewModel
        }
        return mDataBinding?.root
<#else>
        return null
</#if>
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initView()
    }

    override fun initView() {
        mDataBinding?.let { dataBinding ->

        }
    }

    override fun lazyLoad() {

    }

    override fun dealEvent(event: Event?): Boolean {
        // 处理 viewModel 发送过来的事件
        when (event?.code) {
            EVENT_XXX -> {
                val extraObj = event.extraObj
                if (extraObj is String) {
                    LogManager.i(mTag, "XXX 事件 的额外参数 extraObj = $extraObj")
                }
                return true
            }
        }

        return super.dealEvent(event)
    }
}
